package com.dayu.utils;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.reflections.Reflections;

public class ReflectionUtils {

	private static Map<String, Set<Class<?>>> map = new HashMap<String, Set<Class<?>>>();

	public synchronized static Set<Class<?>> getClassOf(String packageName,
			Class<? extends Annotation> annotation) {

		Set<Class<?>> set = map.get(packageName);

		if (set == null) {
			Reflections refs = new Reflections(packageName);
			set = refs.getTypesAnnotatedWith(annotation);
			map.put(packageName, set);
		}

		return set;
	}
}
